﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.DTOs.WhiteStripWeighingHtmlGroup;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.SplitDetails
{
    public class SaleSummaryHander : IRequestHandler<SaleSummaryCommand, Resqults<SaleSummaryDTO>>
    {
        private readonly IBateRepository<SalesWeighing> sale;

        public SaleSummaryHander(IBateRepository<SalesWeighing> sale)
        {
            this.sale = sale;
        }

        public async Task<Resqults<SaleSummaryDTO>> Handle(SaleSummaryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults<SaleSummaryDTO> res = new Resqults<SaleSummaryDTO>();
                var list = from a in sale.GetAll()
                           group new { a } by new { a.ClientID, a.WeightNum, a.NetWeight } into c
                           select new SaleSummaryDTO()
                           {
                               ClientID = c.Key.ClientID,
                               WeightNum = c.Key.WeightNum,
                               NetWeight = c.Key.NetWeight,
                           };
                res.Date = list.ToList();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
